<template>
	<view class="container">
		<view class="avatar">
			<u-avatar :src="authheadnickname.wxheadurl" size="100"> </u-avatar>
		  </view>
	  
		  <view class="nickname">
			{{ authheadnickname.wxnickname ? authheadnickname.wxnickname : "请登录授权"}}
		  </view>



		<view v-if="auth.openid" class="title">
			<text>解除绑定后，将无法使用「微信一键登录」。</text>
		</view>

		<view v-else class="title">
			<text>您暂未授权登录</text>
		</view>

		<u-button text="解除绑定" icon="pushpin" size="small" type="error" :customStyle="btnStyle" @click="wechat"
			v-if="auth.openid" />

		<!-- 消息提醒 -->
		<u-toast ref="notice"></u-toast>

		<!-- 模态框 -->
		<u-modal :show="show" :content="content" showCancelButton @confirm="confirm" @cancel="cancel" />

	</view>
</template>

<script>
export default {
	onLoad() {
		this.auth = this.$u.auth.check()
	},
	onShow()
	{
		var usernicknamelist = uni.getStorageSync("authinfo")
    //如果有登录信息的时候才去覆盖 data数据
    if (usernicknamelist && JSON.stringify(usernicknamelist) != "{}") {
      this.authheadnickname = usernicknamelist;
    }
	},
	created() {

		this.timer = setInterval(() => {

			let a = this.$u.count.check()
			console.log(a)

		}, 5000);

	},
	beforeDestroy() {
		clearInterval(this.timer)
	},
	data() {
		return {
			auth: {},
			authheadnickname:{},
			show: false,
			content: '是否解除微信绑定',
			btnStyle: {
				width: 'auto',
				height: '3em'
			},
		}
	},
	methods: {
		wechat() {
			this.show = true
		},
		//确认
		async confirm() {
			this.show = false

			var result = await this.$u.api.admin.wechat({ adminid: this.auth.id })

			if (result.code) {
				this.$refs.notice.show({
					type: 'success',
					message: result.msg,
					duration: 1200,
					complete: () => {
						//保存登录信息到本地存储 同步保存方法
						uni.removeStorageSync('auth')

						uni.removeStorageSync('qxrouter')

						//返回上一个界面
						uni.$u.route({
							type: 'navigateBack',
							delta: 1
						})

						return false
					}
				})

			} else {
				this.$refs.notice.show({
					type: 'error',
					message: result.msg
				})
			}
		},
		//取消
		cancel() {
			this.show = false
		}
	}
}
</script>

<style>
.container {
	height: 100%;
	margin: 0 80rpx;
	box-sizing: border-box;
}

.avatar {
	text-align: center;
}

.u-avatar {
	margin: 80rpx auto 40rpx;
}

.xcx {
	width: 200rpx;
	height: 200rpx;
	margin: 80rpx auto 40rpx;
	border-radius: 100%;
	overflow: hidden;
}

.nickname {
	font-size: 14px;
	text-align: center;
}

.title {
	text-align: center;
	margin: 40rpx 0;
	font-size: 14rpx;
}

.img-captcha {
	display: block !important;
}

.btn-submit {
	margin-top: 40rpx !important;
}

.href-bindmobile {
	margin-top: 40rpx;
	text-align: center;
	font-size: 14px;
	color: var(--color-primary);
}

.u-form .u-form-item__body__right__message {
	margin-left: 0px !important;
}
</style>